//package com.btobtob.a.biz.user.config;
//
//import com.btobtob.a.biz.user.commonjackson.ZonedDateTimeDeserializer;
//import com.fasterxml.jackson.annotation.JsonAutoDetect;
//import com.fasterxml.jackson.annotation.JsonInclude;
//import com.fasterxml.jackson.annotation.PropertyAccessor;
//import com.fasterxml.jackson.databind.*;
//import com.fasterxml.jackson.databind.module.SimpleModule;
//import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
//import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
//
//import java.math.BigInteger;
//import java.text.SimpleDateFormat;
//import java.time.*;
//import java.time.format.DateTimeFormatter;
//import java.util.TimeZone;
//
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer;
//import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
//import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.Ordered;
//import org.springframework.core.annotation.Order;
//import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//public class JacksonConfig {
//
////    public JacksonConfig() {
////        //super(JacksonConfig.class.getName());
////        this.addSerializer(Long.class, ToStringSerializer.instance);
////        this.addSerializer(Long.TYPE, ToStringSerializer.instance);
////        this.addSerializer(BigInteger.class, ToStringSerializer.instance);
////    }
//
//    private static final String DEFAULT_ZONED_DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSz";
//    private static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
//    private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
//    private static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
//
//
//    @Bean
//    @Primary
//    public ObjectMapper objectMapper() {
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        //日期格式
//        //objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
//        //设置时区
//        objectMapper.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
//        //序列化-忽略null值的属性
//        //objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//        //序列化-允许序列化空对象
//        objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
//        //反序列化-在遇到未知属性的时候不抛出异常
//        //objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//        objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
//        // 禁用日期时间戳格式化
//        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
//        //禁用Jackson库在反序列化日期时自动调整日期到上下文时区的功能。
//        objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
//        JavaTimeModule javaTimeModule = new JavaTimeModule();
//        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//        javaTimeModule.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_ZONED_DATE_TIME_PATTERN)));
//        javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
//        javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
//        javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
//        javaTimeModule.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_ZONED_DATE_TIME_PATTERN)));
//        javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
//        javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
//        javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
//
//        SimpleModule module = new SimpleModule();
//        module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_ZONED_DATE_TIME_PATTERN)));
//        module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_ZONED_DATE_TIME_PATTERN)));
//        module.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
//        module.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
//        objectMapper.registerModule(module);
//
//        objectMapper.registerModule(javaTimeModule).registerModule(new ParameterNamesModule());
//
//        return objectMapper;
//    }
//
//
////    @Bean
////    @Order(Ordered.HIGHEST_PRECEDENCE)
////    public Jackson2ObjectMapperBuilderCustomizer customJackson() {
////        return builder -> {
////            builder.serializerByType(ZonedDateTime.class,
////                    new ZonedDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_ZONED_DATE_TIME_PATTERN)));
////            builder.serializerByType(LocalDateTime.class,
////                    new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
////            builder.serializerByType(LocalDate.class,
////                    new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
////            builder.serializerByType(LocalTime.class,
////                    new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
////            builder.deserializerByType(ZonedDateTime.class,
////                    new ZonedDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_ZONED_DATE_TIME_PATTERN)));
////            builder.deserializerByType(LocalDateTime.class,
////                    new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
////            builder.deserializerByType(LocalDate.class,
////                    new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
////            builder.deserializerByType(LocalTime.class,
////                    new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
////            builder.serializationInclusion(JsonInclude.Include.NON_NULL);
////            builder.failOnUnknownProperties(false);
////            builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
////        };
////    }
//}
